import request from '@/utils/request'
import { getToken } from '@/utils/auth' // get token from cookie
const requesturl = '/cfunc'
const downfileurl = '/download'
const upload = '/upload'

// 通用方法
export function connrequest(CmdCode, data) {
  return request({
    url: requesturl,
    method: 'post',
    data: {
      ...data,
      Header:{
        CmdCode: CmdCode
      },
      Token: getToken()
    }
  })
}

// 下载
export function downloadfile(CmdCode, data) {
  return request({
    url: downfileurl,
    method: 'post',
    responseType:'arraybuffer',
    data: {
      ...data,
      Header:{
        CmdCode: CmdCode
      },
      Token: getToken()
    }
  })
}

// 上传
export function uploadfile(CmdCode, data) {
  return request({
    url: upload,
    method: 'post',
    headers: { 
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + getToken()
    },
    data
  })
}
export function uploadfile2(CmdCode, data) {
  return request({
    url: upload,
    method: 'post',
    data: {
      ...data,
      Header:{
        CmdCode: CmdCode
      },
      Token: getToken()
    }
  })
}


// -- -------------------------------------------------  首页  -------------------------------------------------------------------

// 获取域名审计统计数据
export function GetShadowURLSumGroupByAccessType(data) {
  return request({
    url: requesturl,
    method: 'post',
    data: {
      ...data,
      Header:{
        CmdCode: 'GetShadowURLSumGroupByAccessType'
      },
      Token: getToken()
    }
  })
}

// 今日最近异常域名访问事件
export function GetEventLog(data) {
  return request({
    url: requesturl,
    method: 'post',
    data: {
      ...data,
      Header:{
        CmdCode: 'GetEventLog'
      },
      Token: getToken()
    }
  })
}

// 今日加速流量趋势
export function GetHistorySumStreamLog(data) {
  return request({
    url: requesturl,
    method: 'post',
    data: {
      ...data,
      Header:{
        CmdCode: 'GetHistorySumStreamLog'
      },
      Token: getToken()
    }
  })
}

